﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using Shop.Model;
using Shop.Framework.Keys;
using Shop.Framework.Services;

//Shop.Framework.Control.ProductListItemControl
namespace Shop.Framework.Control {
    public class ProductListItemControl:ViewUserControl<Product> {

        public ProductImage DefaultImage { get; set; }
        public Category CurrentCategory { get; set; }
        public Designer CurrentDesigner { get; set; }

        public bool IsCategory { get; set; }
        public bool IsDesigner { get; set; }

        protected override void OnInit(EventArgs e) {
            try {
                CurrentCategory = ViewData[ShopKey.CurrentCategory] as Category;
                CurrentDesigner = ViewData[ShopKey.CurrentDesigner] as Designer;

                IsCategory = CurrentCategory != null;
                IsDesigner = CurrentDesigner != null;
                
                ProductService service = new ProductService();
                service.RefreshImage(Model);

                DefaultImage = Model.ProductImages.FirstOrDefault(p => p.IsDefault);
                base.OnInit(e);
            } catch (Exception ex) {
                //TODO: Proper messages
                throw ex;
            }
        }
    }
}
